#pragma once
#include "..\Shared\Plugin.h"
#include <Winsock2.h>

class NetworkPlugin;

struct ListenThreadData
{
	bool Close;
	NetworkPlugin *This;
	SOCKET *Socket;
};

class NetworkPlugin : public PluginBase
{
public:
	NetworkPlugin();

	void __stdcall Initialize(PluginManager* Parent, ObjectManager *Objects);
	void __stdcall Dispose();

	bool __stdcall HandleCommand(Command &NewCommand);
	bool SendToPluginManager(Command &NewCommand);
protected:
	WSADATA wsaData;
	SOCKET ListenSocket;
	sockaddr_in service;
	static int __stdcall ListenThread(void *Param);
	static int __stdcall SocketThread(void *Param);
	HANDLE ListenThreadHandle;
	DWORD listenThreadID;
	static HANDLE SocketHANDLEs[64];
	static int numberOfThreads;
	static ListenThreadData * ThreadsData[64];
	ListenThreadData listenThreadData;
private:
	void CreateSocketObject(Command &NewCommand);
	void SendToSocket(Command &NewCommand);
};